<?php

namespace App\Jobs\QiPao\Gift;

use App\Jobs\Job;
use App\Services\Tools\IdempotentConsume;
use Illuminate\Support\Facades\Log;

class SociatyIncomeJob extends Job
{
    protected $data;
    const jobName = 'SociatyIncomeJob';

    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if(env('APP_ENV') != 'production'){
            Log::error('SocialJob:' . json_encode(['time' => getMillisecond(), 'data' => $this->data]));
        }
        try {
            $idempotentConsumeServer =  new IdempotentConsume();
            $data = $this->data;
            $uk = $data['id']??'';
            if($idempotentConsumeServer->checkIdempotentRedisKey(self::jobName,$uk)){
                app('repo_gift')->sync_income($this->data);
            }
        } catch (\Exception $exception) {
            $idempotentConsumeServer->deleteIdempotentRedisKey(self::jobName,$uk);
            Log::error('SocialJob:'.$exception->getMessage());
        }
    }
    
   /* public function fail($exception = null )
    {
        Log::error('SocialJob:'.$exception->getMessage());
    }*/
}
